/*
 * Alexey Danchuk
 * This software is an implementation of the fourth task from tasks.pdf
 * This program takes the date in format dd Month yyyy and prints a
 * day of week.
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Implement a program that prints out the day
 * of the week for a given day.
 *
 * @version 1.01 28 January 2013
 * @author 	Alexey Danchuk
 */

public class Calendar {

	/**
	 * Method to return the number of day of the week, which is
	 * the beginning of the month.
	 * More information about magic numbers can be found at:
	 * http://introcs.cs.princeton.edu/java/21function/Calendar.java.html
	 *
	 * @param month - our month index
	 * @param day - start point
	 * @param year
	 * @return indexDay - day index (0...6)
	 */
	public static int dayDetect(final int month,
		   final int day, final int year) {
		int yr = year - (14 - month) / 12;
		int x = year + yr / 4 - yr / 100 + yr / 400;
		int mth = month + 12 * ((14 - month) / 12) - 2;
		int indexDay = (day + x + (31 * mth) / 12) % 7;
		return indexDay;
	}

	/**
	 * Method to check for leap year.
	 * More information can be found at:
	 * http://introcs.cs.princeton.edu/java/21function/Calendar.java.html
	 *
	 * @param year - year for check
	 * @return - true if the given year is a leap year
	 */
	public static boolean isLeapYear(final int year) {
		if ((year % 4 == 0) && (year % 100 != 0)) {
			return true;
		}
		if (year % 400 == 0) {
			return true;
		}
		return false;
	}

	/**
	 * Method to input date in format dd Month yyyy.
	 *
	 * @return strings - array of dd, Month, yyyy
	 * @throws Exception
	 */
	public static String[] input() throws Exception {
		BufferedReader inputStream = new BufferedReader(new
				InputStreamReader(System.in));
		Scanner inputScan = new Scanner(inputStream.readLine());
		/* To store the date in the appropriate format.
		 * size 3 - dd, Month, yyyy  */
		String[] strings = new String[3];
		int index = 0; // Index to validate the input
		/* This splitting process into tokens and write to an array. */
		while (inputScan.hasNext()) {
			if (index > 2) {
				System.err.println("Check your input!");
				inputStream.close();
				inputScan.close();
			} else {
				strings[index] = inputScan.next();
				index++;
			}
		}
		inputStream.close();
		inputScan.close();
		return strings;
	}

	/**
	 * Method to analyze inputed date.
	 */
	public static void analyze() {
		String[] inputedDate = null;

		try {
			inputedDate = input();
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (inputedDate != null) {
			String[] months = {"", "January", "February", "March",
					"April", "May", "June", "July", "August",
					"September", "October",	"November", "December"};
			/* daysCount[i] = number of days in month i. */
			int[] daysCount = {0, 31, 28, 31, 30, 31, 30,
					31, 31, 30, 31, 30, 31};
			/* Check for leap year.
			 * If a leap year then modifies array daysCount. */
			if (((monthIndex(inputedDate[1], months) == 2)
			     && (isLeapYear(Integer.parseInt(inputedDate[2]))))) {
				daysCount[monthIndex(inputedDate[1],
						             months)] = 29;
			}

			int count = daysCount[monthIndex(inputedDate[1], months)];
			/* Holds start day index from inputed month.
			 * Second parameter is 1 because do not
			 * want to start from zero. */
			int monthStart = dayDetect(monthIndex(inputedDate[1], months),
					1, Integer.parseInt(inputedDate[2]));

			System.out.println(dayOfWeek(Integer.
					                     parseInt(inputedDate[0]),
					                     count, monthStart));
		} else {
			System.err.println("Check your input!");
		}
	}

	/**
	 * Method to get month index.
	 *
	 * @param month - inputed month
	 * @param months - array of month
	 * @return i - month index
	 */
	public static int monthIndex(final String month,
		   final String[] months) {
		for (int i = 0; i < months.length; i++) {
			if (months[i].equals(month)) {
				return i;
			}
		}
		return -1;
	}

	/**
	 * Method to get index weekday for output
	 *
	 * @param inDate - our dd (day number of the month)
	 * @param daysCount - number of days in the month
	 * @param weekDay - on which day begins the month
	 * @return week[dayIndex] - day from week array
	 */
	public static String dayOfWeek(final int inDate,
		   final int daysCount, final int weekDay) {
		String[] week = {"", "Sunday", "Monday", "Tuesday",
				"Wednesday", "Thursday", "Friday", "Saturday"};
		int dayIndex = ((inDate + (weekDay - 1)) % 7);
		return week[dayIndex];
	}

	/**
	 * Main method. Entry point into the program.
	 *
	 * @param args - command-Line arguments, this allows the user to specify
	 *               configuration information when the
	 *               application is launched.
	 */
	public static void main(final String[] args) {
			analyze();
	}
}
